package cate.game.attr;

import cate.common.table.fight.skill.row.SkillBaseRow;
import cate.common.table.item.awakenfairy.row.AwakenFairyBaseRow;
import cate.common.table.item.hero.row.HeroBaseRow;
import cate.common.table.item.staruptask.HeroStarTaskRow;
import cate.game.play.support.PlayBuildContext;
import cate.game.role.bag.awakenfairy.AwakenFairy;
import cate.game.role.bag.awakenfairy.AwakenFairiesOn;
import cate.game.role.bag.hero.Hero;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class AwakenFairysPowerAttrPart extends PowerAttrPart {

    public AwakenFairysPowerAttrPart(){}

    public AwakenFairysPowerAttrPart(PlayBuildContext ctx, AwakenFairiesOn po) {
        if (po == null) {
            return;
        }
        Hero hero = po.owner;
        if (hero == null) {
            return;
        }
        HeroBaseRow heroBaseRow = hero.getTpl(ctx);
        if (heroBaseRow == null) {
            return;
        }


        List<Integer> taskSkills = new ArrayList<>(heroBaseRow.taskSkillList);
        for (Integer taskId : hero.starTaskList) {
            HeroStarTaskRow taskRow = ctx.starUpTaskExcel().task.get(taskId);
            if (taskRow != null) {
                taskSkills.addAll(taskRow.skillList);
            }
        }

        List<Integer> taskSkillsProtos = new ArrayList<>();
        for (Integer skillId : taskSkills) {
            SkillBaseRow baseRow = ctx.skillExcel().base.get(skillId);
            if (baseRow != null) {
                taskSkillsProtos.add(baseRow.protoId);
            }
        }

        FightAttr attr = new FightAttr();
        List<Integer> awakenSkills = new ArrayList<>();
        if (po.awakenFairyMap != null) {
            for (AwakenFairy awakenFairy : po.awakenFairyMap.values()) {
                AwakenFairyBaseRow row = awakenFairy.getTpl(ctx);
                if (row == null) {
                    continue;
                }
                // 仙器基础属性
                attr.add(new FightAttr(row.attrStr));
                if (taskSkillsProtos.contains(row.activeSkillProtoId)) {
                    awakenSkills.add(row.skillId);
                }
            }
        }
        this.attr = attr;
        this.powerExt = 0;
        this.skills = awakenSkills;
    }
}
